var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIConfig"),
    s = t("UIManager"),
    c = t("CommonRandom"),
    p = t("BaseClick"),
    l = cc._decorator,
    d = l.ccclass,
    u = l.property,
    h =
        (l.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.sprite = null;
                e.numLab = null;
                e.canClick = !1;
                e.addRewardList = [];
                return e;
            }
            e.prototype.onLoad = function () {
                t.prototype.onLoad.call(this);
                this.checkKind();
                EVUIEffView.on(EVUIEffView.checkCostUI, this.updateView.bind(this), this);
            };
            e.prototype.updateView = function () {
                this.checkKind();
            };
            e.prototype.openGuild = function () {
                if (!GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][0])) {
                    GuildCache.checkKey = GuildCache.oncecheckId[2][0];
                    GuildCache.overOnceGuid(GuildCache.oncecheckId[2][0]);
                    GuildCache.openGuildView();
                }
            };
            e.prototype.checkOpenGuild = function () {
                GameDataValue.haveNewTip() || this.openGuild();
            };
            e.prototype.onDestroy = function () {
                t.prototype.onDestroy.call(this);
                EVUIEffView.offTarget(this);
            };
            e.prototype.clickIndex = function () {
                this._TouchCancel(null);
            };
            e.prototype._TouchCancel = function () {
                if (!GameDataValue.haveNewTip())
                    if (this.canClick) this.openRewardData();
                    else {
                        this.sprite.node.parent.active = !1;
                        this.sprite.spriteFrame = null;
                    }
            };
            e.prototype.checkKind = function () {
                this.canClick = GameDataValue.getRewardCount() > 0;
                if (this.canClick) {
                    this.numLab.string = "×" + GameDataValue.getRewardCount();
                    var t = GameDataValue.getLastRewardKind();
                    this.viewRewardKind(t);
                    GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][0]) ||
                        (GameDataValue.haveNewTip()
                            ? EVUIEffView.on(EVUIEffView.checkRed, this.checkOpenGuild.bind(this), this)
                            : this.openGuild());
                } else {
                    this.sprite.spriteFrame = null;
                    this.sprite.node.parent.active = !1;
                }
            };
            e.prototype.viewRewardKind = function (t) {
                var e = this;
                this.sprite.node.parent.active = !0;
                var o = CacheDataManager.getRewardKind(t);
                o
                    ? SpriteView.setTaskSprite(this.sprite, o.icon)
                    : this.scheduleOnce(function () {
                          e.viewRewardKind(t);
                      }, 0.5);
            };
            e.prototype.openRewardData = function () {
                QAudio.play(QAudio.ui_button);
            };
            e.prototype.addReward = function () {
                var t = GameDataValue.getOnceRewardKind();
                this.sprite.spriteFrame = null;
                this.sprite.node.parent.active = !1;
                if (t) {
                    var e = CacheDataManager.getRewardKind(t);
                    this.addRewardList.length = 0;
                    if (e) {
                        for (var o = 0; o < e.open_num; o++) {
                            var a = this.parseViewCostume(e.open_costume_rate);
                            a && this.addRewardList.push(a);
                        }
                        SpriteView.setTaskSprite(this.sprite, e.icon);
                        var i = [];
                        for (o = 0; o < this.addRewardList.length; o++) i.push(this.addRewardList[o]);
                        this.addRewardList.length = 0;
                        QAudio.play(QAudio.ui_button);
                        s.default.open(r.UIID.UIReward, {list: i});
                        this.sprite.node.parent.active = !0;
                        this.checkKind();
                        return;
                    }
                    this.sprite.node.parent.active = !1;
                    this.sprite.spriteFrame = null;
                }
            };
            e.prototype.parseViewCostume = function (t) {
                if (t) {
                    for (var e = t.split("|"), o = new c.default(), a = 0; a < e.length; a++) {
                        var i = e[a].split("_");
                        2 == i.length && o.addVal(parseInt(i[1]), i[0]);
                    }
                    return o.getRandomVal();
                }
                return "";
            };
            n([u(cc.Sprite)], e.prototype, "sprite", void 0);
            n([u(cc.Label)], e.prototype, "numLab", void 0);
            return n([d], e);
        })(p.default));
o.default = h;
